﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="Portal.Data.Webparts.WebpartControl" %>
<%@ Import Namespace="Portal.Core.Utils" %>
<%@ Import Namespace="Portal.Data.Entity" %>
<div class="wrap clear_fix">
    <div class="menu_top">
        <div class="tag_mxh">
            <a target="_blank" href="https://facebook.com/TruyenGi" title="Facebook" class="lk_fb"></a>
            <a target="_blank" href="https://plus.google.com/+TruyengiPage/" title="Google+" class="lk_gg"></a>
        </div>
        <div class="sb-toggle-left">
            <div class="navicon-line"></div>
            <div class="navicon-line"></div>
            <div class="navicon-line"></div>
        </div>
        <div class="sb-slidebar">
            <ul>
                <li><a href="/">Trang chủ</a></li>
                <li><a href="/hot/">Hot</a></li>
                <li><a href="/moi-cap-nhat/">Chap mới</a></li>
                <li><a href="/truyen-moi/">Truyện mới</a></li>
                <li class="parentmenu"><a href="/the-loai/">Thể loại</a>
                </li>
                <li><a href="/tac-gia/">Tác giả</a></li>
            </ul>
        </div>
        <ul class="nd_menu_top">
            <li class="home" title="Trang chủ" onclick="location.href='/'">
                <img src="https://lh5.googleusercontent.com/-gQXuUw7XwMM/U_7aqzT_z_I/AAAAAAAAASQ/EiyTZp-tW4Y/h40/home.png" alt="Trang chủ" /></li>
            <li><a href="/hot/">Hot</a></li>
            <li><a href="/moi-cap-nhat/">Chap mới</a></li>
            <li><a href="/truyen-moi/">Truyện mới</a></li>
            <li class="parentmenu"><a href="/the-loai/">Thể loại</a>
                <div class="submenu sub3">
                    <ul>
                        <asp:Repeater ID="HistoryTypes" runat="server">
                            <ItemTemplate>
                                <li><a href="<%#Eval("Url")%>"><%#Eval("FullName")%></a> </li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                </div>
            </li>
            <li><a href="/tac-gia/">Tác giả</a></li>
        </ul>

        <div class="option">
            <div class="ic_option parentmenu">
                <img src="https://lh4.googleusercontent.com/-QW7eQIEnAuI/U-3SR_9X6kI/AAAAAAAAAOw/uKJEaPiQO8E/ic_setting.png">
                <div class="submenu sub2">
                    <ul>
                        <li><a href="/api/">Tài liệu API</a></li>
                    </ul>
                </div>
            </div>
            <div class="ic_option parentmenu">
                <img src="https://lh3.googleusercontent.com/-JJVF_oZwyoM/U-3SPZpMqLI/AAAAAAAAAOA/TLG8JAkKBcA/ic_face.png" />
                <div class="submenu sub1">
                    <ul>
                        <li><a href="/dong-gop-y-kien/">Đóng góp ý kiến</a></li>
                        <li><a href="/request/">Truyện theo yêu cầu</a></li>
                        <li><a href="/aboutus/">Liên hệ</a></li>
                        <li><a href="/rss/">RSS</a></li>
                    </ul>
                </div>
            </div>
            <div class="search">
                <input type="text" class="nd_tk" id="keySearch" name="keySearch" placeholder="Tìm truyện" /><input type="button" class="btn_tk" id="btnSearch" name="btnSearch" />
                <ul id='search-list-result'></ul>
            </div>
        </div>
    </div>
    <!--END menu_top-->
</div>
<!--END wrap-->
<div id="toTop" title="Lên trên"></div>
<script type="text/javascript">
    $(document).mouseup(function (e) {
        var container = $(".search");
        if (!container.is(e.target) // if the target of the click isn't the container...
            && container.has(e.target).length === 0) // ... nor a descendant of the container
        {
            escSearch();
        }
    });
    jQuery(document).ready(function ($) {
        //popover quickinfo
        var dw = getViewport();
        if (dw[0] > 640)
            $("[rel=popover]").popover({ html: true, placement: 'above', offset: 10 });
        
        $('.sb-toggle-left').click(function() {
            $('.sb-slidebar').toggle();
        });
        $('#btnSearch').click(function () {
            onSearch();
        });

        $('#keySearch').keyup(function (e) {
            if (e.keyCode == 13) {
                onSearch();
                return false;
            }
            else {
                clearTimeout($.data(this, 'timer'));
                var wait = setTimeout(fillData, 300);
                $(this).data('timer', wait);
            }
        });

        function fillData() {
            var key = $("#keySearch").val().trim();
            if (key.length <= 2) {
                $('#search-list-result').html('<li class="more">Hãy điền ít nhất 3 ký tự để tự động tìm kiếm</li>').show();
            }
            else {
                $.ajax({
                    url: "/Ajax.aspx",
                    dataType: "json",
                    data: { p: "Book", act: "quicksearch", key: key },
                    success: function (data) {
                        if (data) {
                            var s = "";
                            for (var i in data.label) {
                                s += '<li><a href="' + data.url[i] + '">' + data.label[i] + ' - ' + data.lastUpdateDisplay[i] + ' <div class="quicksearch-visited">' + data.finishDisplay[i] + ' - ' + data.rate[i] + '* - ' + data.view[i] + ' view</div>' + '</a></li>';
                            }
                            if (data.more == true) {
                                s += '<li class="more">... còn nhiều sách không hiển thị, nhấn enter để xem hết</li>';
                            }
                            $('#search-list-result').html(s);
                            $('#search-list-result').show();
                        }
                    },
                    error: function () { escSearch(); }
                });
            }
        }
        function onSearch() {
            var key = $("#keySearch").val().trim();
            if (key.length > 0)
                window.location = "/ket-qua-tim-kiem/key-" + key + "/";
        }
    });

    function escSearch() {
        $("#keySearch").val('');
        $('#search-list-result').hide();
    }
</script>

<script type="text/javascript">
    $(window).scroll(function () {
        var w = $(this).width();
        if (w < 1100) {
            $("#toTop").hide();
            return;
        }
        if ($(this).scrollTop()) {
            $('#toTop').fadeIn();
            $('#toTop').height(84);

            var crtop = $('#toTop').offset().top;
            var ttop = $('.footer').offset().top;            
            if (crtop > ttop) {
                $('#toTop').css({ 'margin-bottom':(crtop-ttop+80)+'px' });
            }
			else{
				$('#toTop').css({ 'margin-bottom':'10px' });
			}
        } else {
            $('#toTop').fadeOut(500);
            $('#toTop').height(0);
        }
    });

    $("#toTop").click(function () {
        $("html, body").animate({ scrollTop: 0 }, 500);
    });
</script>


<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!MyCheck.IsMobileClient())
            {
                HistoryTypes.DataSource = HistoryType.ListAll();
                HistoryTypes.DataBind();
            }
        }
    }
</script>
